<script setup>
import { getCurrentInstance, onMounted, ref } from 'vue';
import { Form, Field, CellGroup, Button } from 'vant';
const unityInput=ref(null);
const unityWindows = ref(null);
let { proxy } = getCurrentInstance();
onMounted(() => {
    addEventListener();
    getData();
})
const onClick = (type) => {
    console.log('点击类型：', unityWindows.value,unityWindows.value.contentWindow);
    unityWindows.value.contentWindow.sendUnityEvent("Item", "ChangeTextColor");
}
const addEventListener = () => {
    console.log("addEventListener");
    window.addEventListener('message', (res) => {
        console.log("接收到的数据：", res.data);
        if (res.data.status == "loading") { 
            console.log("Unity场景加载完成");
        }
        if(res.data.status == "input"){
            unityInput.value = res.data.data||null;
        }
    }, false);
}

const getData = () => {
    let url = 'https://eid.youerp.cn/api/ajax.ashx?oper=Web_GetReserveClient';
    let param = { page: 1, size: 15, text: '' };
    proxy.$api.getData(url, param).then((res) => {
        console.log(res);
        if (res.status == '1') {

        } else {

        }
    })
}
</script>
<template>
    <div class="main">
        <div class="iframe-box">
            <iframe ref="unityWindows" src="../../public/unity/WebGl/index.html?v=1.0.3"
                style="width:100vw; height:100vh;">
                IE：你们都看我干吗，我现在也是支持的
            </iframe>
        </div>
        <div class="uni-tabbar">
            <van-row>
                <van-col span="8">span: 8</van-col>
                <van-col span="8">span: 8</van-col>
                <van-col span="8">
                    <van-button type="primary" @click="onClick">主要按钮</van-button></van-col>
            </van-row>
        </div>
    </div>
</template>
<style scoped lang="less">
.main {
    background-color: #ecebeb;
}

.iframe-box {
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0;

    iframe {
        border: 0 none;
    }
}

.form-box {
    background-color: #fff;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    position: relative;
    z-index: 15;
}

.uni-tabbar {
    position: fixed;
    bottom: 0;
    width: 100vw;
}
</style>